package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.PasswordDTO;
import com.tianya.domain.dto.UserRequestDTO;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.domain.vo.UserVO;
import com.tianya.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author TianYaGuoKe
 * @date 2025/5/25 11:29
 * @description UserController
 */
@Api("用户管理")
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @ApiOperation("获取用户信息")
    @GetMapping("/info/{id}")
    public Results<UserVO> getUserInfo(@PathVariable Long id) {
        return Results.success(userService.getUserInfo(id));
    }

    @ApiOperation("修改密码")
    @PutMapping("/password")
    public Results modifyPassword(@RequestBody PasswordDTO passwordDTO) {
        userService.modifyPassword(passwordDTO);
        return Results.success();
    }

    @ApiOperation("修改用户信息")
    @PutMapping("/info/{id}")
    public Results editUserInfo(@PathVariable Long id, @RequestBody UserVO userVO) {
        userService.editUserInfo(id,  userVO);
        return Results.success();
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/{id}")
    public Results deleteUser(@PathVariable Long id) {
        userService.removeById(id);
        return Results.success();
    }

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Results<PageResultVO<UserVO>> page(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestBody UserRequestDTO userRequestDTO) {
        return Results.success(userService.pageUser(pageNum, pageSize, userRequestDTO));
    }
}
